<div class="overlay" ng-hide="showGrid"></div>
<div class="loading-img" ng-hide="showGrid"></div>

<div ng-show="showGrid">
    <div class="form-group">
        <div class="input-group col-md-5 filter">
            <span class="input-group-addon"><i class="glyphicon glyphicon-filter"></i></span>
            <input type="text" class="form-control" ng-model="filter">
            <span class="input-group-addon btn btn-default" ng-disabled="filter.length == 0" ng-click="filter = ''"><i class="fa fa-times"></i></span>
        </div>
    </div>

    <table class="coc-grid table table-striped table-bordered table-condensed table-hover">
        <tr ng-hide="unsets.add">
            <th class="col-md-1" colspan="{{columns.length + 1}}">
                <a href="{{add}}" class="btn btn-primary">Novo</a>
                <!--  show buttons top extras  --> 
                <a ng-show="buttons.top.length" ng-repeat="bt in buttons.top" target="{{bt.target}}" class="{{bt.class}}" href="{{bt.link}}">{{bt.label}}</a> 
       
        </th>
        </tr>
        <tr>
            <th ng-repeat="column in columns" ng-class="column.class" ng-click="setOrderBy(column.name)">
        <div>
            {{column.header|| column.name}}
            <i class="fa" ng-class="{'fa-sort-alpha-desc': orderBy.asc, 'fa-sort-alpha-asc': !orderBy.asc}" ng-show="orderBy.field == '{{column.name}}'"></i>
        </div>
        </th>
        <th >A&ccedil;&otilde;es</th>
        </tr>

      
        <tr ng-repeat="object in objects| orderBy:orderBy.field:!orderBy.asc | filter: filter">

            <td ng-repeat="column in columns" ng-switch on="object.editMode" >
                <div ng-switch-default ng-switch on="!column.lookup" ng-click="toggleEditMode(object)">
                    <span ng-switch-default  grid-callback  grid-call-value="getDataCall(column.name,object[column.name],object)">{{object[column.name]}}</span>

                    <span ng-switch-when="false">{{ object[column.lookup.table][column.lookup.value]}}</span>
                </div>

                <div ng-switch-when="true" ng-switch on="!column.lookup">
                    <input ng-switch-default ng-model="object[column.name]" model-change-blur ng-disabled="column.autoincrement"
                           class="form-control" />
                    <select ng-switch-when="false" 
                            ng-options="l[column.lookup.key] as l[column.lookup.value] for l in getLookupData(column.lookup.table) | orderBy: column.lookup.orderBy.field:!column.lookup.orderBy.asc" 
                            ng-model="object[column.name]" class="form-control"></select>
                </div>
            </td>
            <td>
                <div class="btn-toolbar" ng-switch on="object.editMode">
                    <div class="btn-group" ng-switch-default>
                       
                        <a  ng-show="edit" href="{{edit}}{{object[key]}}" class="btn btn-default fa fa-edit"></a>

                        
                        <a  ng-show="actionsDataGrid.length" ng-repeat="ac in actionsDataGrid" 
                         class="btn btn-default {{ac.icon}}" 
                        title="{{ac.title}}" href="{{ac.url | replaceValueId:object[key]}}">{{url.label}}</a>
                        <i ng-show="buttons.line.length" ng-repeat="bt  in buttons.line" 
                        class="btn btn-default {{bt.icon}}"
                        ng-click="gridCall(bt.click || {},object)"></i>
                        
                        
                        <i  ng-hide="unsets.delete" class="btn btn-default fa fa-trash-o" ng-click="deleteObject(object)"></i>
                    </div>
                    <div class="btn-group" ng-switch-when="true">
                        <i class="btn btn-default fa fa-save" ng-click="updateObject(object);
                                toggleEditMode(object);"></i>
                        <i class="btn btn-default fa fa-times" ng-click="toggleEditMode(object)"></i>
                    </div>
                </div>
            </td>



        </tr>
    </table>

</div>